package com.example.arithmeticleetcode.leetcode.dec;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-12-25 09:16
 **/
public class Demo25 {

    public static void main(String[] args) {
        int[] target = {2, 3, 4};
        System.out.println(buildArray(target, 4));
        int[] target1 = {3, 4};
        System.out.println(buildArray(target1, 4));
    }

    public int findContentChildren(int[] g, int[] s) {
        if (s == null || s.length == 0) return 0;
        Arrays.sort(g);
        Arrays.sort(s);
        int count = 0;
        int gIndex = 0;
        int sIndex = 0;
        while (gIndex < g.length && sIndex < s.length) {
            if (g[gIndex] <= s[sIndex]) {
                count++;
                gIndex++;
                sIndex++;
            } else {
                sIndex++;
            }
        }
        return count;
    }

    public static List<String> buildArray(int[] target, int n) {
        List<String> list = new ArrayList<>();
        int count = 1;
        for (int i = 0, len = target.length; i < len; i++) {
            if (count == target[i]) {
                list.add("Push");
                count++;
            } else {
                while (count < target[i]) {
                    list.add("Push");
                    list.add("Pop");
                    count++;
                }
                i--;
            }
        }
        return list;
    }
}
